/*
 * @Description:
 * @Version: 2.0
 * @Autor: zss
 * @Date: 2025-01-08 16:22:38
 * @LastEditors: zss
 * @LastEditTime: 2025-05-26 10:31:14
 */
import { ifs, ts } from '@/services';
import { N_drivingSet } from './type';

class T_cmd {
  // 主组件箱
  private compBox: ifs.I_compBox;

  // 主组件ID
  private compID: string;

  // 主组件实例
  private self: N_drivingSet.cDrivingSet;

  private task = new ts.T_task(5000);

  // 当前轮询是否开启
  public isOpenTask: boolean = false;

  // 主组件created里初始化
  public init(self: N_drivingSet.cDrivingSet, compBoxInfo: ifs.I_compBoxInfo) {
    this.self = self;
    this.compBox = compBoxInfo.TcompBox;
    this.compID = compBoxInfo.compID;
  }

  public getTcmd(): T_cmd {
    return this;
  }

  public startTask() {
    this.task.addTask(this.readData);
    this.task.startTask();
    this.isOpenTask = true;
  }

  public stopTask() {
    this.task.delTask(this.readData);
    this.task.stopTask();
    this.isOpenTask = false;
  }

  private readData = () => {
    this.self.updateData();
  };
}

interface I_cmd extends T_cmd {}

export { I_cmd, T_cmd };
